package com.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.R;
import com.app.bean.NewsListBean;

import java.util.List;

public class NewsListAdapter extends BaseAdapter {

    private Context context;
    private List<NewsListBean.ListBean> listBean;

    // 右键自动创建构造方法
    public NewsListAdapter(Context context, List<NewsListBean.ListBean> listBean) {
        this.context = context;
        this.listBean = listBean;
    }

    @Override
    //得到数据的行数
    public int getCount() {
        return listBean.size();
    }

    @Override
    //根据 i 得到某一行的记录
    public Object getItem(int i) {
        return listBean.get(i);
    }

    @Override
    //得到某一条记录的ID
    public long getItemId(int i) {
        return listBean.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = View.inflate(context, R.layout.item_news,null);
        TextView newsTitle = view.findViewById(R.id.tv_title);
        TextView newsDate = view.findViewById(R.id.tv_date);
        newsTitle.setText(listBean.get(i).getTitle()+"");
        newsDate.setText(listBean.get(i).getDate()+"");
        return view;
    }



}
